package me.lc.filarSocksUniform.offer;

import me.lc.filarSocksUniform.FilarSocksUniformMonthlyActivity;
import me.lc.filarSocksUniform.util.ResourceManager;
import android.content.Context;
import android.widget.Toast;

import com.uucun.adsdk.UUAppConnect;
import com.uucun.adsdk.UpdatePointListener;

public class AppjoyOfferUtil implements IOffer, UpdatePointListener {
	private boolean isInited = false;

	// private boolean isRequesting = false;

	@Override
	public void init(Context context) {
		if (!isInited) {
			isInited = true;
			UUAppConnect.getInstance(context).initSdk();
		}
	}

	@Override
	public void dispose(Context context) {
		UUAppConnect.getInstance(context).exitSdk();
	}

	@Override
	public void showOffer(Context context) {
		UUAppConnect.getInstance(context).showOffers();
	}

	@Override
	public void updateCoins(Context context) {
		// if (!isRequesting) {
		// isRequesting = true;
		UUAppConnect.getInstance(context).getPoints(this);
		// }
	}

	@Override
	public void onError(String arg0) {
		// isRequesting = false;
	}

	@Override
	public void onSuccess(String currencyName, int bonus) {
		// isRequesting = false;
		if (bonus > 0) {
			try {
				ResourceManager.currentGold += bonus;
				ResourceManager.saveGold();
				// 直接消费掉
				UUAppConnect.getInstance(
						FilarSocksUniformMonthlyActivity.instance).spendPoints(
						bonus, this);
				FilarSocksUniformMonthlyActivity.instance.updateGold();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}
